/*
 * @Author: yanjikun
 * @Date: 2022-04-28 16:02:37
 * @LastEditors: yanjikun
 * @LastEditTime: 2022-05-12 16:40:35
 * @Description: file content
 */

import { isFunction } from '@/utils/is'
import { error } from '@/utils/log'
import { Slots } from 'vue'

export const getSlot = (slots: Slots, slot = 'default', data?: any) => {
  if (!slots || !Reflect.has(slots, slot)) {
    return null
  }
  if (!isFunction(slots[slot])) {
    error(`${slot} is not a function!`)
    return null
  }
  const slotFn = slots[slot]
  if (!slotFn) return null
  return slotFn(data)
}
